package com.markyao.controller.recos;

import com.markyao.recos.conf.RecosConfService;
import com.markyao.vo.ConfParam;
import com.markyao.vo.PageParams;
import com.markyao.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/recos/conf")
public class RecosConfController {
    @Autowired
    RecosConfService recosConfService;
    @GetMapping("autowired")
    public Result autowiredConf(@RequestParam("serverPort")String serverPort,
                                @RequestParam("conf")String conf,
                                @RequestParam("appName")String appName,
                                @RequestParam("coname")String coname,
                                HttpServletRequest request){
        return recosConfService.autowiredConfig(appName,conf,serverPort,coname,request);
    }

    @GetMapping("getBindConf")
    public Result getBindConf(@RequestParam("appName")String appName){
        return recosConfService.getBindConf(appName);
    }
    @GetMapping
    public Result getConf(@RequestParam("appName")String appName){
        return recosConfService.getConfEvent(appName);
    }
    @GetMapping("get")
    public Result getConfByDataIdAndGroupId(@RequestParam("dataId")String dataId,@RequestParam(value = "groupId",required = false)String groupId){
        return recosConfService.getConfByDataIdAndGroupId(dataId,groupId);
    }
    @PostMapping("list")
    public Result getConfs(@RequestBody PageParams pageParams){
        return recosConfService.getConfs(pageParams);
    }

    @PostMapping("refreshConf")
    public Result refreshConf(@RequestBody ConfParam conf){
        return recosConfService.refreshConf(conf);
    }
    //客户端通知已经刷新成功
    @GetMapping("refreshOk")
    public Result refreshOk(@RequestParam("appName")String appName){
        return recosConfService.refreshOk(appName);
    }

    //客户端询问是否有刷新事件
    @GetMapping("isRefresh")
    public Result isRefresh(@RequestParam("appName")String appName){
        return recosConfService.isRefresh(appName);
    }

    @GetMapping("registDataIdAndAppName")
    public Result registDataIdAndAppName(@RequestParam("appName")String appName,@RequestParam("dataId")String dataId){
        return recosConfService.registDataIdAndAppName(appName,dataId);
    }
}
